﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApp.Services;

namespace WebApp.Controllers
{
    [Produces("application/json")]
    [Route("api/MongoDbCache")]
    public class MongoDbCacheController : Controller
    {
        private readonly MongoDbCacheService _mongoDbCacheService;
        public MongoDbCacheController(MongoDbCacheService mongoDbCacheService)
        {
            _mongoDbCacheService = mongoDbCacheService;
        }


        // GET api/values/key
        [HttpGet("{key}")]
        public string Get(string key)
        {
            return _mongoDbCacheService.Get(key)?.ToString() ?? "null";
        }


        // POST api/values
        [HttpPost]
        public void Post([FromBody]string key)
        {
            _mongoDbCacheService.Add(key, DateTime.Now.Ticks);

        }


    }
}